package com.hliushi.learn.controller;

import com.hliushi.learn.jms.MsgProducer;
import com.hliushi.learn.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.jms.Destination;

/**
 * @ClassName ActiveMqController
 * @Description ActiveMq controller
 * @Author liushi
 * @Date 2021/7/9 9:12
 * @Version V1.0
 **/
@Api("ActiveMq Controller")
// @RestController
@RequestMapping("/activemq")
public class ActiveMqController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ActiveMqController.class);

    @Resource
    private MsgProducer msgProducer;

    @Resource
    private Destination queue;

    @Resource
    private Destination topic;


    /**
     * 点对点消息生成
     *
     * @return jsonResult
     */
    @ApiOperation("点对点消息生成")
    @GetMapping("/send/queue")
    public JsonResult<Void> sendQueueMessage() {
        LOGGER.info("==== 开始发送点对点消息 ====");
        msgProducer.sendMessage(queue, "Queue: hello activemq!");
        return new JsonResult<>();
    }

    /**
     * 发布/订阅消息生成
     *
     * @return jsonResult
     */
    @ApiOperation("发布/订阅消息生成")
    @GetMapping("/send/topic")
    public JsonResult<Void> sendTopicMessage() {
        LOGGER.info("==== 开始发送订阅消息 ====");
        msgProducer.sendMessage(topic, "Topic: hello activemq!");
        return new JsonResult<>();
    }

}
